import java.awt.*;
import java.awt.geom.AffineTransform;

import javax.swing.ImageIcon;

public class Player {

	public static final double baseSpeed = 0.5;

	private double x;
	private double y;
	public double heading;
	Rectangle rect;
	Image plane;
	AffineTransform affineTransform = new AffineTransform(); 
	
	public Player(int x, int y) {
		this.x = x;
		this.y = y;
		plane = new ImageIcon("Images/Plane.png").getImage();

		rect = new Rectangle(x, y, 100, 80);
		
	}

	public double getX() {
		return x;
	}

	public void setX(double x) {
		this.x = x;
	}

	public double getY() {
		return y;
	}

	public void setY(double y) {
		this.y = y;
	}

	public void moveUp(double n) {
		
		y -= n;
		rect.setLocation((int) Math.round(x), (int) (Math.round(y)-6));
	}

	public void moveUpRight(double n) {
		
		double dist = n / Math.sqrt(2);
		y -= dist;
		x += dist;
		rect.setLocation((int) Math.round(x), (int) (Math.round(y)-6));
	}

	public void moveRight(double n) {
		
		x += n;
		rect.setLocation((int) Math.round(x), (int) (Math.round(y)-6));
	}

	public void moveDownRight(double n) {
		
		double dist = n / Math.sqrt(2);
		y += dist;
		x += dist;
		rect.setLocation((int) Math.round(x), (int) (Math.round(y)-6));
	}

	public void moveDown(double n) {
		
		y += n;
		rect.setLocation((int) Math.round(x), (int) (Math.round(y)-6));
	}

	public void moveDownLeft(double n) {
		
		double dist = n / Math.sqrt(2);
		y += dist;
		x -= dist;
		rect.setLocation((int) Math.round(x), (int) (Math.round(y)-6));
	}

	public void moveLeft(double n) {
		
		x -= n;
		rect.setLocation((int) Math.round(x), (int) (Math.round(y)-6));
	}

	public void moveUpLeft(double n) {
		
		double dist = n / Math.sqrt(2);
		y -= dist;
		x -= dist;
		rect.setLocation((int) Math.round(x), (int) (Math.round(y)-6));
	}

	public void draw(Graphics2D g) {
//		g.drawImage(plane, 10, 10, PlanesCore.planes);
		g.drawImage(plane, affineTransform, PlanesCore.planes);
		
	}
	
	public void movePlayer(int mousex, int mousey){
		double angle = PlanesPanel.findAngle(getX(),getY(),getX(),0); 
		heading = angle;
		affineTransform.setToTranslation(getX(), getY());
		
	}
	
	public Bullet shoot() {
		
		double bulletX = x;
		double bulletY = y+15;
	    return (new Bullet(bulletX, bulletY, heading, 1));
	
	}
	
public Bullet shoot2() {
		
		double bulletX = x+100;
		double bulletY = y+15;
	    return (new Bullet(bulletX, bulletY, heading, 1));
	
	}

}